import { NativeProvider } from './../../providers/native/native';
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { BusiProvider } from '../../providers/busi/busi';

/**
 * Generated class for the PasswordchangePage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-passwordchange',
  templateUrl: 'passwordchange.html',
})
export class PasswordchangePage {
  oldpassword:any;
  newpassword:any;
  confirmpassword:any;
  constructor(public navCtrl: NavController, public navParams: NavParams,private native: NativeProvider,private busi: BusiProvider) {
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad PasswordchangePage');
  }
  save(){
    if(this.oldpassword == null || this.oldpassword == ''){
      this.native.alert("旧密码为空！");
      return;
    }
    if(this.newpassword == null || this.newpassword == ''){
      this.native.alert("新密码为空！");
      return;
    }
    if(this.confirmpassword == null || this.confirmpassword == ''){
      this.native.alert("确认密码为空！");
      return;
    }
    if(this.newpassword!=this.confirmpassword){
      this.native.alert("两次输入的新密码不一致！");
      return;
    }
    this.busi.passwordchange(this.oldpassword, this.newpassword).subscribe(
      data=>{
        this.native.showToast("修改成功!");
        this.navCtrl.pop();
      },
      error=>{

      }
    )
  }

}
